//将数据源存入session
function sessionData() {
  if (sessionStorage.getItem('initialData') == null) {
    let allData = JSON.stringify(bookData)
    sessionStorage.setItem('initialData', allData)
  }
}
//当前对应菜单样式
function nowPageOut(obj) {
  let num = obj.siblings().length + 1
  obj.parent().css({
    'height': num * 50 + 'px'
  })
  obj.children().last().css({
    'transform': 'rotate(180deg)'
  })
  obj.css({
    'background-color': 'rgb(87,111,225)'
  })
}
//导航菜单下拉样式及icon样式
function pullDown(obj) {
  let num = obj.siblings().length + 1
  $('.menu').height(50)
  $('.icon-xiala').css({
    'transform': 'rotate(0deg)'
  })
  obj.parent().css({
    'height': num * 50 + 'px'
  })
  obj.children().last().css({
    'transform': 'rotate(180deg)'
  })
}
//导航菜单跳转地址
function jumpPage(obj) {
  $('li').css({
    'background-color': 'rgb(93, 128, 253)'
  })
  obj.css({
    'background-color': 'rgb(87,111,225)'
  })
  switch (obj.attr('page-data')) {
    case 'page1':
      location.href = './hsgl.html';
      break
    case 'page2':
      location.href = './jygl.html';
      break
    case 'page3':
      location.href = './xsrk.html';
      break
    case 'page4':
      location.href = './cqhs.html';
      break
    case 'page5':
      location.href = './xsgl.html';
      break
    case 'page6':
      location.href = './tszt.html';
      break
    case 'page7':
      location.href = './yhxx.html';
      break
    case 'page8':
      location.href = './hmdyh.html';
      break
    case 'page9':
      location.href = './jyjl.html';
      break
    case 'page10':
      location.href = './chtx.html';
      break
  }
  let page
  sessionStorage.setItem('page', obj.attr('page-data'))
}
// //数据渲染
// function showData(pageNum) {
//   $('tbody').html('')
//   let showData = pagedata.slice((pageNum - 1) * eachNum, pageNum * eachNum)
//   showData.forEach(item => {
//     $('tbody').append(`
//       <tr>
//         <th><input type="checkbox"></th>
//         <td>${item.jykh}</td>
//         <td>${item.yhm}</td>
//         <td>${item.hyts}</td>
//         <td>${item.tsbh}</td>
//         <td>${item.zz}</td>
//         <td>${item.lb}</td>
//         <td>${item.bq}</td>
//         <td>${item.jyrq}</td>
//         <td>${item.sfxj}</td>
//         <td>${item.xjts}</td>
//         <td>${item.yhrq}</td>
//         <td>${item.sjhsrq}</td>
//         <td>${item.cqts}</td>
//         <td>${item.sfds}</td>
//         <td><span class='change'>编辑</span><span>|</span><span class='del'>删除</span></td>
//       </tr>
//     `)
//   })
// }
//页码渲染
function showPage(maxPage) {
  $('.page-num').remove()
  for (let i = 1; i <= maxPage; i++) {
    $('.pagination').children().last().before(`<li><a href="#" class='page-num'>${i}</a></li>`)
  }
  $('.page-num').on('click', function () {
    goPage($(this).text())
  })
}
//当前页码样式
function pageColor(nowPageNum) {
  $('.page-num').css({
    'background-color': 'white',
    'color': 'rgb(214,214,214)'
  })
  $('.page-num').eq(nowPageNum - 1).css({
    'background-color': 'rgb(64,158,255)',
    'color': 'white'
  })
}
//页面跳转
function goPage(goNum) {
  nowPageNum = goNum
  showData(nowPageNum)
  pageColor(nowPageNum)
  checkAll = true
  swapCheck()
}
//上一页
function prePage() {
  if (nowPageNum > 1) {
    nowPageNum--
    goPage(nowPageNum)
  }
}
//下一页
function nextPage() {
  if (nowPageNum < maxPage) {
    nowPageNum++
    goPage(nowPageNum)
  }
}
//每页展示数据条数
function downPage(obj) {
  $('#dropdownMenu2').text(obj.text())
  eachNum = parseInt(obj.attr('value'))
  maxPage = Math.ceil(resultData.length / eachNum)
  showPage(maxPage)
  nowPageNum = 1
  goPage(nowPageNum)
}
//复选框全选
function swapCheck() {
  if (checkAll) {
    $('input[type="checkbox"]').each(function () {
      this.checked = false
      checkAll = false
    })
  } else {
    $('input[type="checkbox"]').each(function () {
      this.checked = true
      checkAll = true
    })
  }
  ischecks()
}